package com.rdc.qingkou.model;

import com.rdc.qingkou.contract.ChangePasswordContract;
import com.rdc.qingkou.entity.ModifyUserInfoResult;
import com.rdc.qingkou.entity.Result;
import com.rdc.qingkou.model.imodel.OnHttpCallBack;
import com.rdc.qingkou.retrofitService.IPersonalSettingsService;
import com.rdc.qingkou.utils.MyUtils;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by WaxBerry on 2017/11/12.
 */

public class ChangePasswordModel implements ChangePasswordContract.IModel {

    @Override
    public void showPassword(Integer userId,final OnHttpCallBack<ModifyUserInfoResult> callBack) {

        MyUtils.getRetrofitProvider("")
                .create(IPersonalSettingsService.class)
                .getUserInfo(userId)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.newThread())
                .subscribe(new Observer<ModifyUserInfoResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ModifyUserInfoResult modifyUserInfoResult) {
                        callBack.onSuccessful(modifyUserInfoResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        callBack.onFaild(e.toString());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    @Override
    public void changePassword(String userId, String oldPassword, String newPassword, String confirmPassword, final OnHttpCallBack<Result> callBack) {

        MyUtils.getRetrofitProvider("")
                .create(IPersonalSettingsService.class)
                .modifyPassword(userId,oldPassword,newPassword,confirmPassword)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.newThread())
                .subscribe(new Observer<Result>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(Result result) {
                        callBack.onSuccessful(result);
                    }

                    @Override
                    public void onError(Throwable e) {
                        callBack.onFaild(e.toString());
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }
}
